<?php

namespace Mallocu\NuitInfoBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Mallocu\NuitInfoBundle\Entity\Monument
 * 
 * @author Rémi PIOTAIX <remi.piotaix@gmail.com>
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Mallocu\NuitInfoBundle\Repository\MonumentRepository")
 */
class Monument {

    const REPO = 'MallocuNuitInfoBundle:Monument';

    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string $nom
     *
     * @ORM\Column(name="nom", type="string", length=150)
     */
    private $nom;

    /**
     * @var \DateTime $dateCons
     *
     * @ORM\Column(name="dateCons", type="string", length=30)
     */
    private $dateCons;

    /**
     * @var string $localisation
     *
     * @ORM\Column(type="string", length=100)
     */
    private $region;

    /**
     * @var string $localisation
     *
     * @ORM\Column(type="string", length=100)
     */
    private $departement;

    /**
     * @var string $localisation
     *
     * @ORM\Column( type="string", length=100)
     */
    private $ville;

    /**
     * @var string $twitter
     *
     * @ORM\Column(name="twitter", type="string", length=50, nullable=true)
     */
    private $twitter;

    /**
     * @var Collection $images
     *
     * @ORM\OneToMany(targetEntity="Mallocu\NuitInfoBundle\Entity\Image", mappedBy="monument", cascade={"persist"})
     */
    private $images;

    /**
     * @var Collection $types
     *
     * @ORM\ManyToMany(targetEntity="Mallocu\NuitInfoBundle\Entity\Type", inversedBy="monuments")
     */
    private $types;

    /**
     * @var string $resume
     *
     * @ORM\Column(name="resume", type="string", length=255)
     */
    private $resume;

    /**
     * @var string $description
     *
     * @ORM\Column(name="description", type="text")
     */
    private $description;

    public function __construct() {
        $this->types = new ArrayCollection();
        $this->images = new ArrayCollection();
    }

    public function __toString() {
        return $this->nom;
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId() {
        return $this->id;
    }

    /**
     * Set nom
     *
     * @param string $nom
     * @return Monument
     */
    public function setNom($nom) {
        $this->nom = $nom;

        return $this;
    }

    /**
     * Get nom
     *
     * @return string 
     */
    public function getNom() {
        return $this->nom;
    }

    /**
     * Set dateCons
     *
     * @param \DateTime $dateCons
     * @return Monument
     */
    public function setDateCons($dateCons) {
        $this->dateCons = $dateCons;

        return $this;
    }

    /**
     * Get dateCons
     *
     * @return \DateTime 
     */
    public function getDateCons() {
        return $this->dateCons;
    }

    public function getRegion() {
        return $this->region;
    }

    public function setRegion($region) {
        $this->region = $region;
    }

    public function getDepartement() {
        return $this->departement;
    }

    public function setDepartement($departement) {
        $this->departement = $departement;
    }

    public function getVille() {
        return $this->ville;
    }

    public function setVille($ville) {
        $this->ville = $ville;
    }

    /**
     * Set twitter
     *
     * @param string $twitter
     * @return Monument
     */
    public function setTwitter($twitter) {
        $this->twitter = $twitter;

        return $this;
    }

    /**
     * Get twitter
     *
     * @return string 
     */
    public function getTwitter() {
        return $this->twitter;
    }

    /**
     * Set images
     *
     * @param integer $images
     * @return Monument
     */
    public function setImages($images) {
        $this->images = $images;

        foreach ($images as $i) {
            $i->setMonument($this);
        }

        return $this;
    }

    public function addImage(Image $i) {
        $this->getImages()->add($i);
        $i->setMonument($this);
    }
    
    public function removeImage(Image $i){
        $this->getImages()->removeElement($i);
    }

    /**
     * Get images
     *
     * @return integer 
     */
    public function getImages() {
        return $this->images;
    }

    public function imageAccueil() {
        $images = $this->getImages();
        if ($images->isEmpty()) {
            return new NoImage();
        }

        return $this->getImages()->get(mt_rand(0, $images->count() - 1));
    }

    /**
     * Set types
     *
     * @param integer $types
     * @return Monument
     */
    public function setTypes($types) {
        $this->types = $types;

        return $this;
    }
    
    public function hasImages(){
        return $this->getImages()->count();
    }

    /**
     * Get types
     *
     * @return integer 
     */
    public function getTypes() {
        return $this->types;
    }

    /**
     * Set resume
     *
     * @param string $resume
     * @return Monument
     */
    public function setResume($resume) {
        $this->resume = $resume;

        return $this;
    }

    /**
     * Get resume
     *
     * @return string 
     */
    public function getResume() {
        return $this->resume;
    }

    /**
     * Set description
     *
     * @param string $description
     * @return Monument
     */
    public function setDescription($description) {
        $this->description = $description;

        return $this;
    }

    /**
     * Get description
     *
     * @return string 
     */
    public function getDescription() {
        return $this->description;
    }

}
